import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:x_common_utils/utils/inkWell_util.dart';
import 'package:get/get.dart';
import 'package:xinxuan/utils/color_util.dart';

class InputDialogUtil extends StatelessWidget {

  final String title;
  final String hintText;
  final ValueChanged<String> onChenge;
  final Function onSubmit;
  final String defaultValue;
  final int? maxLength;

  InputDialogUtil({
    required this.title,
    required this.hintText, 
    required this.onChenge, 
    required this.onSubmit, 
    this.defaultValue = '',
    this.maxLength
  });

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Container(
        width: 320.w,
        decoration: BoxDecoration(
          color: bgWhiteColor,
          borderRadius: BorderRadius.circular(16.w)
        ),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            Container(
              padding: EdgeInsets.symmetric(vertical: 32.h, horizontal: 20.w),
              child: Column(
                children: [
                  Text(
                    title,
                    style: TextStyle(
                      color: textBlackColor,
                      fontSize: 20.sp
                    ),
                  ),
                  Container(
                    height: 44.h,
                    margin: EdgeInsets.only(top: 20.h),
                    padding: EdgeInsets.symmetric(horizontal: 16.w),
                    decoration: BoxDecoration(
                      border: Border.all(
                        width: 1,
                        color: lineColor
                      ),
                      borderRadius: BorderRadius.circular(8.w)
                    ),
                    child: TextField(
                      controller: TextEditingController(text: defaultValue),
                      decoration: InputDecoration(
                        border: OutlineInputBorder(borderSide: BorderSide.none),
                        // border: UnderlineInputBorder(borderSide: BorderSide(color: Colors.transparent)),
                        // enabledBorder: UnderlineInputBorder(borderSide: BorderSide(color: Colors.transparent)),
                        // focusedBorder: UnderlineInputBorder(borderSide: BorderSide(color: Colors.transparent)),
                        contentPadding: EdgeInsets.zero,
                        counterText: '',
                        hintText: hintText,
                        hintStyle: TextStyle(
                          fontSize: 14.sp,
                          color: textSubtitleColor_102,
                        )
                      ),
                      cursorColor: textBlackColor,
                      style: TextStyle(
                        fontSize: 14.sp,
                        color: textBlackColor
                      ),
                      onChanged: (String value) => onChenge(value),
                      maxLength: maxLength,
                      onSubmitted: (String value) {
                      },
                    ),
                  )
                ],
              ),
            ),
            Container(
              height: 55.h,
              decoration: BoxDecoration(
                border: Border(
                  top: BorderSide(
                    width: 1.w,
                    color: lineColor
                  )
                )
              ),
              child: Row(
                children: [
                  InkWellUtil.shakeProofInkWell(Container(
                    width: 150.w,
                    alignment: Alignment.center,
                    decoration: BoxDecoration(
                      border: Border(
                        right: BorderSide(
                          width: 1.w,
                          color: lineColor
                        )
                      )
                    ),
                    child: Text(
                      '取消',
                      style: TextStyle(
                        color: textSubtitleColor,
                        fontSize: 16.sp
                      ),
                    ),
                  ), () {
                    Get.back();
                  }),
                  InkWellUtil.shakeProofInkWell(Container(
                    width: 150.w,
                    alignment: Alignment.center,
                    child: Text(
                      '确定',
                      style: TextStyle(
                        color: mainTextColor,
                        fontSize: 16.sp
                      ),
                    ),
                  ), () => onSubmit())
                ],
              ),
            )
          ],
        ),
      ),
    );
  }
}